<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
</head>

<body>
    <!-- 引入vue的js文件，放在文件的头部 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>


    <div id="root">

        <input type="text" placeholder="请输入姓名过滤" v-model="keyWord">
        <!-- 遍历数组 -->
        <h2>遍历数组</h2>
        <ul>
            <!--                    使用计算属性 -->
            <li v-for="(p, index) in filterPersons" :key="p.id">
                {{index}} - {{p.id}} - {{p.name}}
            </li>
        </ul>



    </div>


</body>
<script type="text/javascript">
    Vue.config.productionTip = false

    const vm = new Vue({
        el: "#root",
        data: {
            keyWord: '',
            persons: [
                { id: '001', name: '张三', age: 18 },
                { id: '002', name: '李四', age: 19 },
                { id: '003', name: '王五', age: 20 },
            ],
        },
        computed: {
            filterPersons() {
                return this.persons.filter((p) => {
                    return p.name.indexOf(this.keyWord) !== -1
                })
            }
        }
    })
</script>

</html>